package com.itheima.service;
import com.itheima.common.R;
import com.itheima.mapper.StaffMapper;
import com.itheima.pojo.StaffPage;
import com.itheima.pojo.Staff;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author Envy
 */
@Service
public class StaffService {
    @Resource
    private StaffMapper staffMapper;

    /**
     * 登录功能
     */
    public Staff login(Staff staff) {
        return staffMapper.login(staff);
    }


    /**
     * 新增员工
     */
    public int addStaff(Staff staff) {
        return staffMapper.addStaff(staff);
    }

    /**
     * 分页查询员工
     */
    public R<StaffPage> pageQuery(String name, Integer page, Integer pageSize) {

        System.out.println(name + "=======debug");
        List<StaffPage> pageQuery = staffMapper.pageQuery(name, page, pageSize);

        StaffPage page1 = new StaffPage();
        //设置所有页面的总条数
        page1.setTotal(staffMapper.count());
        //设置每页显示的数据条数
        page1.setSize(pageSize);

        if (pageQuery != null) {
            page1.setCurrent(page);
            page1.setRecords(pageQuery);
            return R.success(page1);
        }
        return R.error("暂无数据");
    }

    /**
     * 根据id查询员工
     */
    public Staff selectInfo(String id) {
        return staffMapper.selectInfo(id);
    }

    /**
     * 修改员工信息
     */
    public int update(Staff staff) {
        return staffMapper.update(staff);
    }
}
